<?php

class Contacto extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library(array(
            'form_validation'
        ));
        $this->load->model(array(
            'contacto_model'
        ));
    }
    
    public function index() {
        $data['title'] = 'Contacto';
        
        $this->form_validation->set_rules('nombre', 'Nombre', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
        $this->form_validation->set_rules('mensaje', 'Mensaje', 'required');
        
        if($this->form_validation->run() == FALSE) {
            
        } else {
            $datos = array(
                'nombre' => $this->input->post('nombre'),
                'email' => $this->input->post('email'),
                'motivo' => $this->input->post('motivo'),
                'mensaje' => $this->input->post('mensaje')
            );
            
            $this->contacto_model->set($datos);
        }
        
        $this->load->view('layout/header', $data);
        $this->load->view('contacto/index');
        $this->load->view('layout/footer');
    }
}
?>
